package util

import (
	"encoding/json"

	"github.com/golang/protobuf/proto"
)

// JSON2PB transform json to proto
func JSON2PB(form_json_str string, to_pb proto.Message) error {
	// json字符串转pb
	return json.Unmarshal([]byte(form_json_str), &to_pb)
}

// PB2JSON transform proto to json
func PB2JSON(from_pb proto.Message, to_json_str string) error {
	json_str, err := json.Marshal(from_pb)
	if err == nil {
		to_json_str = string(json_str)
	}
	return err
}
